


<template>
    <div class="model-form">
        <el-page-header @back="goBack" content="增加">
        </el-page-header>
        <div class="model-content">
            <el-form ref="ruleForm" :rules="rules" :model="form" label-width="160px">
                <el-row :gutter="10">
    <el-col :span="22">
            <el-form-item label="会员卡名称"  prop="name">
        <el-input v-model="form.name" name="name">
        </el-input>
            </el-form-item>

    </el-col>
    <el-col :span="22">
            <el-form-item label="会员卡标识"  prop="key">
        <el-input v-model="form.key" name="key">
        </el-input>
            </el-form-item>

    </el-col>
    <el-col :span="22">
            <el-form-item label="会员卡类型"  prop="cardType">
        <nb-select catalog="cardType" v-model="form.cardType"></nb-select>
            </el-form-item>

    </el-col>
    <el-col :span="22">
            <el-form-item label="有效期限"  prop="expiryType">
        <nb-select catalog="expiryType" v-model="form.expiryType"></nb-select>
            </el-form-item>

    </el-col>
    <el-col :span="22">
            <el-form-item label="卡封面"  prop="logo">
        <avatar v-model="form.logo"></avatar>
            </el-form-item>

    </el-col>
    <el-col :span="22">
            <el-form-item label="卡背景"  prop="background">
        <avatar v-model="form.background"></avatar>
            </el-form-item>

    </el-col>
    <el-col :span="7">
            <el-form-item label="原价"  prop="money">
        <el-input v-model="form.money" name="money">
        </el-input>
            </el-form-item>

    </el-col>
    <el-col :span="7">
            <el-form-item label="优惠价"  prop="discount">
        <el-input v-model="form.discount" name="discount">
        </el-input>
            </el-form-item>

    </el-col>
    <el-col :span="7">
            <el-form-item label="推荐提成"  prop="backMoney">
        <el-input v-model="form.backMoney" name="backMoney">
        </el-input>
            </el-form-item>

    </el-col>
    <el-col :span="7">
            <el-form-item label="折扣"  prop="rebate">
        <el-input v-model="form.rebate" name="rebate">
        </el-input>
            </el-form-item>

    </el-col>
    <el-col :span="7">
            <el-form-item label="天数"  prop="day">
        <el-input-number v-model="form.day" name="day" :min="0" :max="9999999" style="width: 100%;"></el-input-number>
            </el-form-item>

    </el-col>
    <el-col :span="22">
            <el-form-item label="会员权益"  prop="note">
        <el-input v-model="form.note" name="note" type="textarea"></el-input>
            </el-form-item>

    </el-col>
    <el-col :span="22">
            <el-form-item label="备注"  prop="demo">
        <el-input v-model="form.demo" name="demo" type="textarea"></el-input>
            </el-form-item>

    </el-col>

                    <el-col :span="22">
                        <el-form-item>
                            <el-button @click="goBack">取消</el-button>
                            <el-button type="primary" @click="add">确定</el-button>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </div>
    </div>
</template>

<script>
    import common from "@/mixins/common.js";
    import {ElLoading} from "element-plus";

    import nbSelect from "@/components/nbSelect.vue";
    import avatar from "@/components/avatar.vue";

    export default {
        name: "VipCardTemplate_add",
        mixins: [common],
        components: {nbSelect, avatar},
        data() {
            return {
                form: {
                    name: '',
                    key: '',
                    cardType: '',
                    expiryType: '',
                    logo: '',
                    background: '',
                    money: '',
                    discount: '',
                    backMoney: '',
                    rebate: '',
                    day: '',
                    note: '',
                    demo: ''                },
                rules: {
                    name: [
                        {required: true, message: '请输入会员卡名称', trigger: 'blur'}
                    ],
                    key: [
                        {required: true, message: '请输入会员卡标识', trigger: 'blur'}
                    ],
                    cardType: [
                        {required: true, message: '请输入会员卡类型', trigger: 'blur'}
                    ],
                    expiryType: [
                        {required: true, message: '请输入有效期限', trigger: 'blur'}
                    ],
                }
            }
        },
        methods: {
            async add() {
                try {
                    let valid = await this.$refs["ruleForm"].validate();
                    if (!valid) {
                        return;
                    }
                } catch (e) {
                    return;
                }

                await this.addData();
            },
            async addData() {
                let data = this.form;
                const loading = ElLoading.service({
                    lock: true,
                    text: '数据处理中',
                    background: 'rgba(0, 0, 0, 0.7)',
                })

                let res = await this.$http.form("/vipCardTemplate/create", data);

                loading.close();

                if (res.code !== 200) {
                    this.$message.error(res.msg);
                    return;
                }

                this.$message({
                    message: '添加数据成功',
                    type: 'success'
                });
                this.$router.go(-1);
            },

        },
        mounted() {
        }
    }

</script>

<style scoped>
</style>